package com.xoa.controller.cms;

import com.xoa.service.cms.CmsChannelPublishService;
import com.xoa.service.cms.core.FileUtils;
import com.xoa.util.common.wrapper.BaseWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
@RequestMapping("cmsChannelPub")
public class CmsChannelPublishController {

    @Autowired
    CmsChannelPublishService cmsChannelPublishService;
    @ResponseBody
    @RequestMapping("/toPub")
    public BaseWrapper toPub(HttpServletRequest request, HttpServletResponse response){
        BaseWrapper baseWrapper=new BaseWrapper();
        String channelIds = FileUtils.getString(request.getParameter("channelIds"), "");
        try {
            if(channelIds.endsWith(",")){
                channelIds = channelIds.substring(0,channelIds.length()-1);
            }
            String[] chIds = channelIds.split(",");
            for(String id:chIds){
                cmsChannelPublishService.toPub(request,Integer.parseInt(id),true);
            }
            baseWrapper.setFlag(true);
            baseWrapper.setMsg("栏目发布成功！");
        } catch (Exception e) {
            baseWrapper.setMsg("发布失败！");
            e.printStackTrace();
        }
        return baseWrapper;
    }
}
